package com.patternsbox.structural.composite;

import com.patternsbox.ActionTemplate;

public class CompositeAction extends ActionTemplate {

	@Override
	protected void doAction() {
		// Create a tree structure
		Component root = new Composite("root");
		root.add(new Leaf("Leaf A"));
		root.add(new Leaf("Leaf B"));
		Component comp = new Composite("Composite X");
		comp.add(new Leaf("Leaf XA"));
		comp.add(new Leaf("Leaf XB"));
		root.add(comp);
		root.add(new Leaf("Leaf C"));
		// Add and remove a leaf
		Component leaf = new Leaf("Leaf D");
		root.add(leaf);
		root.remove(leaf);
		// Recursively display tree
		root.display(1);
	}
}
